﻿using UnityEngine;
using System.Collections;

public class SelectableTraitSeal : MonoBehaviour {
    public bool m_bSelectable;
    public bool m_bChoosen;

    public TraitData m_Trait;

    bool m_bInformOn;
	// Use this for initialization
	void Start () {
        


	}

    // Update is called once per frame
    void Update()
    {

	}

    void OnHover(bool isOver)
    {
        if (isOver)
        {
            if (!m_bInformOn)
            {
                ResourceMgr.GetInstance().CreateInformBox(m_Trait.m_strName, m_Trait.m_strDesc);
                m_bInformOn = true;
            }
        }
        if (!isOver && m_bInformOn)
        {
            m_bInformOn = false;
            for (int i = 0; i < GameObject.Find("InformBoxUI").transform.childCount; ++i)
            {
                Destroy(GameObject.Find("InformBoxUI").transform.GetChild(i).gameObject);
            }
        }
    }

    void OnClick()
    {
        if (m_bSelectable)
        {
            for (int i = 0; i < transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.arrayTrait.Length; ++i)
            {
                if (transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.arrayTrait[i].m_strSpriteName == "")
                {
                    transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.arrayTrait[i] = m_Trait;
                    transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.iTraitPoint -= 1;

                    transform.parent.GetComponent<TraitSelPaper>().PointCheck();
                    transform.parent.parent.GetComponent<UnitNoteDetails>().NoteTraitInit();
                    InitSeal();
                    break;
                }
            }
        }
    }

    public void InitSeal()
    {
        for (int i = 0; i < transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.arrayTrait.Length; ++i)
        {
            if (transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.arrayTrait[i] != null)
            {
                if (transform.parent.parent.GetComponent<UnitNoteDetails>().unitStatus.m_unitData.arrayTrait[i].m_iID == m_Trait.m_iID)
                {
                    GetComponent<UISprite>().color = new Color(1, 1, 1, 1);
                }
            }
        }

        GetComponent<UISprite>().spriteName = m_Trait.m_strSpriteName;
    }
}
